package cn.sanshuilin.kst.system.provider.write.dao;

import cn.sanshuilin.kst.system.provider.bean.Comment;
import org.springframework.stereotype.Repository;

import javax.persistence.Query;
import java.util.List;

/**
 * @author greenlee
 * @version v1.0
 * @create 创建时间: 2017-11-30 10:10
 * Copyright 2017  by 三水林科技有限公司
 **/
@Repository
public class CommentReq extends AbstractJpaDao<Comment> {


    public List<Comment> getComments(int nPageIndex, int nPageSize, String strKeyword, String strPubMemberID, String strToMemberID, String strShareID){
            String hql = " SELECT c FROM Comment c  WHERE c.Content LIKE :Keyword  ";
            if(!"".equals(strPubMemberID)){
                hql += "AND c.PubMemberID = :PubMemberID" ;
            }
            if(!"".equals(strToMemberID)){
                hql += "AND c.ToMemberID = :ToMemberID" ;
            }
            if(!"".equals(strShareID)){
                hql += "AND c.ShareID = :ShareID" ;
            }
            hql += " ORDER BY c.PubDate  DESC";
            Query query =entityManager.createNativeQuery(hql,Comment.class);
            query.setParameter("Keyword", "%"+strKeyword+"%");
            if(!"".equals(strPubMemberID)){
                query.setParameter("PubMemberID", strPubMemberID);
            }
            if(!"".equals(strToMemberID)){
                query.setParameter("ToMemberID", strToMemberID);
            }
            if(!"".equals(strShareID)){
                query.setParameter("ShareID", strShareID);
            }
            List<Comment> comments = query.getResultList();

        return comments;
    }


}
